import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:riverpod_t/page/home/data/model/detail_model_entity.dart';
import 'package:riverpod_t/routers/navigator_utils.dart';
import 'package:riverpod_t/widget/custom_button.dart';

/// 导航栏内容组件
class AppBarContent extends StatelessWidget {
  final DetailModelData? detailModel;
  final double? scrollOffset;
  final double? appBarAlpha;

  const AppBarContent({super.key, this.detailModel, this.scrollOffset, this.appBarAlpha});

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        // 返回按钮
        CustomButton(
          width: 48.w,
          height: kToolbarHeight,
          onPressed: () => NavigatorUtils.pop(context),
          iconName: "assets/images/back_black.png",
          iconColor: appBarAlpha == 1 ? Colors.black : Colors.white,
          iconFit: BoxFit.cover,
          iconWidth: 22.w,
          iconHeight: 22.w,
        ),

        // 标题和追书按钮
        Expanded(
          child: Row(
            children: [
              Expanded(
                child: Padding(
                  padding: EdgeInsets.only(right: 10.w),
                  child: Text(
                    detailModel?.title ?? '',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontSize: 15.sp),
                  ),
                ),
              ),
              if ((scrollOffset ?? 0) >= 150.h) _buildFollowButton(),
            ],
          ),
        ),

        // 分享按钮
        CustomButton(
          width: 48.w,
          height: kToolbarHeight,
          onPressed: () {},
          iconName: "assets/images/ZCIcon_share_normal@3x.png",
          iconColor: appBarAlpha == 1 ? Colors.black : Colors.white,
          iconFit: BoxFit.cover,
          iconWidth: 22.w,
          iconHeight: 22.w,
        ),
      ],
    );
  }

  Widget _buildFollowButton() {
    return Container(
      width: 40.w,
      height: 20.h,
      decoration: BoxDecoration(
        color: Colors.orange,
        border: Border.all(width: 1.w, color: Colors.orange),
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(6.h),
          bottomRight: Radius.circular(6.h),
        ),
      ),
      alignment: Alignment.center,
      child: Text(
        '追书',
        style: TextStyle(color: Colors.white, fontSize: 12.sp, fontWeight: FontWeight.w500),
      ),
    );
  }
}
